package com.itheima.UDP.UDP接收协议;




import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class ServiceDemo3 {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds=new DatagramSocket(120);
        while (true) {
            byte[] bys = new byte[1024];
            DatagramPacket dp = new DatagramPacket(bys, bys.length);
            ds.receive(dp);

            byte[] data = dp.getData();
            int length = dp.getLength();
            System.out.println(new String(data, 0, length));

           /* DatagramPacket dp = new DatagramPacket(new byte[1024 * 1024], 1024 * 1024);

            int length=dp.getLength();
            System.out.println(new String(dp.getData(),0,length));*/
        }
        // ds.close();
    }
}
